package com.hut.bms.controller;
import com.hut.bms.model.*;
import com.hut.bms.service.SelectBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RequestMapping("/BMS")
@RestController
public class SelectBookIController {
    @Autowired
    private SelectBookService selectBookService;

    @RequestMapping("/getBookList")
    public Result<PageResult<BookInfo>> getBookList(PageRequest pageRequest) {
        //打印从前端参数传入到后端的日志
        log.info("展示图书列表，接收到的参数pageRequest：{}", pageRequest);
        //参数校验
//        if(pageRequest.getPageNum() == null) {
//            return
//        }
        //返回的是当前页面的图书列表和图书的总数
        PageResult<BookInfo> booklist =  selectBookService.selectBookByPage(pageRequest);
        return Result.success(booklist);
    }

    //查看以id为参数的图书信息
    @RequestMapping("/queryBookById")
    public BookInfo queryBookById(Integer bookId) {
        return selectBookService.getBookById(bookId);
    }
}
